import request from '@/utils/request'

// 获取订单列表
export const getOrderListService = (params) => {
    return request.get('/orders/list', { params })
}

// 获取订单详情
export const getOrderDetailService = (id) => {
    return request.get(`/orders/${id}`)
}

// 添加订单
export const addOrderService = (data) => {
    return request.post('/orders', {
        vendorId: data.vendorId,
        status: data.status,
        orderDetails: data.orderDetails.map(item => ({
            productName: item.productName,
            quantity: item.quantity,
            price: item.price
        }))
    })
}

// 更新订单
export const updateOrderService = (data) => {
    return request.put(`/orders`, {
        id: data.id,
        vendorId: data.vendorId,
        status: data.status,
        orderDetails: data.orderDetails.map(item => ({
            orderItemId: item.orderItemId,
            productName: item.productName,
            quantity: item.quantity,
            price: item.price
        }))
    })
}

// 删除订单
export const deleteOrderService = (id) => {
    return request.delete(`/orders/${id}`)
}

// 批量删除订单
export const batchDeleteOrderService = (ids) => {
    return request.delete('/orders/batch', { data: ids })
}